package system;

import java.util.Scanner;

/**
 * @author rosekon
 * @version 3.0
 * @date 2022年3月16日
 */
public class publicTavernTest3 {
    public static void main(String[] args) {
        int length = 3;
        //姓名
        String names[] = new String[length];
        //订单信息
        String[] messages = new String[length];
        //时间
        int[] times = new int[length];
        //地址
        String[] addresses = new String[length];
        //订单状态
        boolean[] states = new boolean[length];
        //总金额
        int[] sumPrices = new int[length];
        //记录订单信息数
        int count = 0;
        //菜品信息
        String[] dishNames = new String[]{"大盘鸡", "麻婆豆腐", "时令蔬菜", "鸡蛋汤"};
        int[] dishPrices = new int[]{68, 28, 18, 10};
        int[] praiseNums = new int[4];
        Scanner in = new Scanner(System.in);
        a:
        while (true) {
            System.out.println(
                    "\t欢迎使用\"大众酒馆外卖系统\"\n" +
                            "----------------------------------\n" +
                            "\t\t1.\t我\t要\t订\t餐\n" +
                            "\t\t2.\t查\t看\t餐\t车\n" +
                            "\t\t3.\t签\t收\t订\t单\n" +
                            "\t\t4.\t删\t除\t订\t单\n" +
                            "\t\t5.\t菜\t品\t评\t价\n" +
                            "\t\t6.\t退\t出\t系\t统\n" +
                            "----------------------------------");
            System.out.print("请输入序号：");
            int no = in.nextInt();
            switch (no) {
                case 1: {
                    if (count < length) {
                        System.out.println("\t\t----订餐----");
                        System.out.print("请输入姓名：");
                        names[count] = in.next();
                        //展示菜单
                        System.out.println("\t\t\t菜单");
                        System.out.println("----------------------------------");
                        System.out.println("序号\t名称\t\t价钱 \t点赞");
                        //打印菜单
                        for (int j = 0; j < dishNames.length; j++) {
                            System.out.println((j + 1) + "\t" + dishNames[j] + "\t" + dishPrices[j] + "元\t" + praiseNums[j]);
                        }
                        //用户选择菜品
                        int dishNo = 0;
                        System.out.print("请选择菜品序号：");
                        while ((dishNo = in.nextInt()) < 1 || dishNo > 4) {
                            System.out.println("请重新输入正确的序号！");
                            System.out.print("请选择菜品序号：");
                        }
                        System.out.print("请输入份数：");
                        int dishDeal = in.nextInt();
                        messages[count] = dishNames[dishNo - 1] + dishDeal + "份";
                        System.out.print("请选择送餐时间（10:00-20:00）：");
                        int time = 0;
                        while ((time = in.nextInt()) < 10 || time > 20) {
                            System.out.println("不在送餐时间，请重新输入！");
                            System.out.print("请选择送餐时间（10:00-20:00）：");
                        }
                        times[count] = time;
                        System.out.print("请输入送餐地址：");
                        addresses[count] = in.next();
                        //计算金额，满68元免配送费
                        int price = dishPrices[dishNo - 1] * dishDeal;
                        int tip = price >= 68 ? 0 : 5;
                        int sumPrice = price + tip;
                        sumPrices[count] = sumPrice;
                        System.out.println("订餐成功！");
                        //订单信息加一
                        count++;
                        continue;
                    }
                    System.out.println("订单存满了，请先去删除订单！");
                    break;
                }
                case 2: {
                    if (count == 0) {
                        System.out.println("餐车没信息，请去主菜单点餐！");
                        continue;
                    }
                    System.out.println("\t\t----查看餐车----");
                    System.out.println("序号\t订餐人 \t餐品信息\t送餐时间\t送餐地址\t总金额\t订单状态");
                    for (int i = 0; i < count; i++) {
                        System.out.println((i + 1) + "\t" + names[i] + "\t" + messages[i] + "\t" + times[i] + "点" + "\t" + addresses[i] + "\t" + sumPrices[i] + "元\t" + states[i]);
                    }
                    break;
                }
                case 3: {
                    if (count == 0) {
                        System.out.println("餐车没信息，请去主菜单点餐！");
                        continue;
                    }
                    System.out.println("\t\t----签收订单----");
                    System.out.print("请输入要签收的订单序号：");
                    int orderNo = 0;
                    while ((orderNo = in.nextInt()) > count || orderNo < 1) {
                        System.out.println("订单不存在！");
                        System.out.print("请输入要签收的订单序号：");
                    }
                    if (states[orderNo - 1]) {
                        System.out.println(orderNo + "号已签收，不能重复签收！");
                        continue;
                    }
                    states[orderNo - 1] = true;
                    System.out.println(orderNo + "号订单签收成功！");
                    break;
                }
                case 4: {
                    if (count == 0) {
                        System.out.println("餐车没信息，请去主菜单点餐！");
                        continue;
                    }
                    System.out.println("\t\t----删除订单----");
                    System.out.print("请输入要签收的订单序号：");
                    int delOrderNo = 0;
                    while ((delOrderNo = in.nextInt()) > count || delOrderNo < 1) {
                        System.out.println("订单不存在！");
                        System.out.print("请输入要删除的订单序号：");
                    }
                    if (!states[delOrderNo - 1]) {
                        System.out.println(delOrderNo + "号订单尚未签收，不能删除！");
                        continue;
                    }

                    //删除订单
                    for (int i = delOrderNo - 1; i < length - 1; i++) {
                        names[i] = names[i + 1];
                        messages[i] = messages[i + 1];
                        times[i] = times[i + 1];
                        addresses[i] = addresses[i + 1];
                        sumPrices[i] = sumPrices[i + 1];
                        states[i] = states[i + 1];
                    }
                    //最后一位清空
                    names[length - 1] = null;
                    messages[length - 1] = null;
                    times[length - 1] = 0;
                    addresses[length - 1] = null;
                    sumPrices[length - 1] = 0;
                    states[length - 1] = false;
                    System.out.println("删除订单成功！");
                    count--;
                    break;
                }
                case 5: {
                    System.out.println("\t\t----评价菜品----");
                    //显示菜单信息
                    System.out.println("序号\t名称\t\t价钱 \t点赞");
                    for (int j = 0; j < dishNames.length; j++) {
                        String praiseNum = praiseNums[j] > 0 ? praiseNums[j] + "赞" : "0";
                        System.out.println((j + 1) + "\t" + dishNames[j] + "\t" + dishPrices[j] + "元\t" + praiseNum);
                    }
                    System.out.print("请选择您要点赞的商品序号：");
                    int num = in.nextInt();
                    //点赞数加1
                    praiseNums[num - 1]++;
                    System.out.println("点赞成功！");
                    break;
                }
                case 6: {
                    System.out.println("----退出系统----");
                    break a;
                }
                default: {
                    System.out.println("无效数字,返回主菜单重新选择");
                    break;
                }
            }
        }
        System.out.println("欢迎下次光临!");
    }
}
